import axios from "axios";

// 使用create([config])方法创建axios实例，其中config参数为axios最基本的配置信息
const axiosObj = axios.create({
    baseURL:'http://localhost:19000'
})

axiosObj.defaults.withCredentials = true


import {useloginUserStore} from "./store/loginUserInfo.js";

axiosObj.interceptors.request.use(function (config) {
    const loginUserStore = useloginUserStore();

    // 对包含非英文字符的请求头值进行编码
    if (loginUserStore.name) {
        config.headers.MyName = encodeURIComponent(loginUserStore.name);
    }
    if(loginUserStore.saTokenInfo.tokenName) {
        config.headers[loginUserStore.saTokenInfo.tokenName] = loginUserStore.saTokenInfo.tokenValue;
    }
    return config;
    }, function (error) {
    return Promise.reject(error);
});

export default axiosObj;